package pdamh.view;

import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import pdamh.controller.UnidadesController;
import pdamh.model.exceptions.PDAMHException;

public class TelaNovaSubUnidade extends JDialog {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JComboBox jComboBox = null;
	private JTextField jTextField = null;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private String projeto = "";
	UnidadesController controler = null;
	private JButton jButtonOK = null;
	private JButton jButtonCancelar = null;

	/**
	 * This is the default constructor
	 */
	public TelaNovaSubUnidade() {
		super((JFrame)null,true);
		initialize();
	}
	
	public TelaNovaSubUnidade(UnidadesController con, String projeto) {
		super((JFrame)null,true);
		controler=con;
		this.projeto=projeto;
		initialize();
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(283, 214);
		this.setContentPane(getJContentPane());
		this.setTitle("Nova SubUnidade");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(13, 79, 75, 20));
			jLabel1.setText("Nome");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(38, 30, 50, 20));
			jLabel.setText("Unidade");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJComboBox(), null);
			jContentPane.add(getJTextField(), null);
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(getJButtonOK(), null);
			jContentPane.add(getJButtonCancelar(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
			jComboBox.setBounds(new Rectangle(129, 30, 121, 25));
			if(!projeto.isEmpty()&& controler!=null){
				try {
					for (String uni : controler.getUnidades(projeto)) {
						jComboBox.addItem(uni);
					}
				} catch (PDAMHException e) {}
			}
		}
		return jComboBox;
	}
	public String getUnidade(){
		return getJComboBox().getSelectedItem().toString();
	}
	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(129, 79, 121, 20));
		}
		return jTextField;
	}
	public String getNome(){
		return getJTextField().getText();
	}
	/**
	 * This method initializes jButtonOK	
	 * 	
	 * @return javax.swing.JButton	
	 */
	protected JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setBounds(new Rectangle(43, 130, 57, 26));
			jButtonOK.setText("OK");
		}
		return jButtonOK;
	}

	/**
	 * This method initializes jButtonCancelar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancelar() {
		if (jButtonCancelar == null) {
			jButtonCancelar = new JButton();
			jButtonCancelar.setBounds(new Rectangle(124, 130, 90, 26));
			jButtonCancelar.setText("Cancelar");
			jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return jButtonCancelar;
	}

}  //  @jve:decl-index=0:visual-constraint="177,41"
